package com.knowif.backend.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.pojo.TUser;
import com.knowif.pojo.TUserExample;
import com.knowif.search.SearchCondition;
import com.knowif.service.User_service;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;

/**
 * @author xingyao
 * @Description: 用户实现
 */
@Service
public class TUserService {
	
	
	@Autowired
	private User_service user_service;

	/**
	 * 保存普通用户
	 * 
	 * @param user
	 * @return
	 */
	public RestBean<?> saveNormalUser(TUser user) {
		return user_service.saveNormalUser(user);
	}

	/**
	 * 条件查询用户
	 *
	 * @param searchCondition
	 * @return
	 * @throws Exception 
	 */
	public RestBean<?> selectUser(SearchCondition searchCondition) throws Exception {
		if(searchCondition == null){
			return RestBean.buildError("请输入查找信息");
		}
		TUserExample tUserExample;
		tUserExample = ExampleUtil.buildExample(new TUserExample(), searchCondition);
		List<TUser> users = user_service.selectUser(tUserExample);
		if (users != null && users.isEmpty()) {
			return RestBean.buildError("没有找到对应的信息");
		}
		return RestBean.buildSuccess(users);
	}
	
	
	
	
	/**
	 * @author: xingyao 
	 * @Description:  用于个人中心查找
	 * @param userId
	 * @return
	 */
	public RestBean<?> selectTUserInfo(Integer userId){
		if(userId == null){
			return RestBean.buildError("请输入用户id",RestBean.NOTUSERID);
		}
		return user_service.selectUserInfo(userId);
	}

	/**
	 * 更新用户信息
	 * @param tUser
	 * @return
	 */
	public RestBean updateUserInfo(TUser tUser){
		int i = user_service.updateUserInfo(tUser);
		if(i > 0){
			return RestBean.buildSuccess("更新成功");
		}
		return RestBean.buildError("更新失败");
	}
	
}








